package com.bawei.mvvm.widget

import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.bawei.mvvm.App

//spanCount:列表2   space：间隙 10
class MyItemDecoration(private val spanCount:Int,private val space:Int):RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        outRect.top = space
        var  position = parent.getChildAdapterPosition(view)//获得当前item的下标
        if(position % spanCount == 0){//判断是否为最左边的
            outRect.left = 0
            outRect.right = space/2
        }else if(position % spanCount == spanCount-1){//判断是否为最右边的
            outRect.right = 0
            outRect.left = space/2
        }else{
            outRect.left = space/2
            outRect.right = space/2
        }
    }
}